<template>
  <div class="shop">
     <div class="shop_condition">
       <el-button-group>
      <el-button size='small' @click="changeStatus(0)">全部</el-button>
      <el-button size='small' @click="changeStatus(5)">已付款</el-button>
      <el-button size='small' @click="changeStatus(10)">已核销</el-button>
      <el-button size='small' @click="changeStatus(20)">已失效</el-button>
    </el-button-group>
    
    <!-- <p class="text_ordertype">订单类型：</p>
    <el-select v-model="form.order_type" size='small'
    class="detail_select"
      placeholder="订单类型">
      <el-option label="全部"
        value=""></el-option>
      <el-option label="爆款商品"
        value="1"></el-option>

         <el-option label="拼团"
        value="10"></el-option>
         <el-option label="会员专享商品"
        value="15"></el-option>
         <el-option label="普通商品"
        value="25"></el-option>
    </el-select> -->

    <div class="search">
      <el-input size='small' class="input" v-model="form.orderId" placeholder="输入订单ID搜索" clearable></el-input>
          <el-button size='small' class="search_btn" type="primary" @click="searchvouchlist">搜索</el-button>
    </div>

    <div class="search">
      <el-input class="input" size='small' v-model="form.productId" placeholder="输入商品ID搜索" clearable></el-input>
    </div>

    <div class="search">
      <el-input class="input" size='small' v-model="form.title" placeholder="输入商品名称搜索" clearable></el-input>
  
    </div>
     </div>

    <el-table
      :data="tableData"
      class="order_table"
      style="width:100%"
      max-height="630"
      :cell-style="tc"
      :header-cell-style="tccolor"
    >
      <el-table-column prop="orderId" label="订单ID" width='140'></el-table-column>
      <el-table-column prop="productId" label="商品ID"></el-table-column>
      <el-table-column prop="productTitle" label="商品名称" width ='120'></el-table-column>
      <el-table-column prop="nickName" label="下单用户" width='140'></el-table-column>
      <el-table-column prop="sellerName" label="所属小店"></el-table-column>
      <el-table-column label="原价/实付价" width='120'>
        <template slot-scope="scope">{{scope.row.totalAmount}}/{{scope.row.actualAmount}}</template>
      </el-table-column>
      <!-- <el-table-column prop="rebate_money_yuan" label="返红包数"></el-table-column> -->
      <el-table-column label="购买数" prop="quantity"></el-table-column>
      <el-table-column label="订单类型" width='120' prop="orderTypeText">
        <!-- <template slot-scope="scope">
          <p v-if="scope.row.order_type==1">爆款商品订单</p>
          <p v-if="scope.row.order_type==5">现金券订单</p>
          <p v-if="scope.row.order_type==10">拼团订单</p>
          <p v-if="scope.row.order_type==15">会员专享订单</p>
          <p v-if="scope.row.order_type==20">满减券订单</p>
           <p v-if="scope.row.order_type==25">普通商品订单</p>
        </template> -->
      </el-table-column>
      <el-table-column label="订单状态" prop="orderStatusText">
        <!-- <template slot-scope="scope">
          <p v-if="scope.row.order_status==1">待支付</p>
          <p v-if="scope.row.order_status==5">已支付</p>
          <p v-if="scope.row.order_status==10">已核销</p>
          <p v-if="scope.row.order_status==15">已取消</p>
          <p v-if="scope.row.order_status==20">已失效</p>
        </template> -->
      </el-table-column>
      <el-table-column label="创建时间" width='160'>
        <template slot-scope="scope">
          <p>{{parseTime(scope.row.createdAt)}}</p>
      
        </template>
        
      </el-table-column>

      <el-table-column label="操作" fixed='right'>
        <template slot-scope="scope">
          <el-button size="mini" @click="openOrderDetail(scope.row.orderId)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-col :span="24">
      <div class="pagination">
        <el-pagination
          background
          @current-change="pageChange"
          :current-page="form.pageNum"
          :page-size="form.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-col>
  </div>
</template>

<script>
import { shopMallOrderlist } from "@/api/order";
// import store from "@/store";
export default {
  data() {
    return {
      form: {
        // order_status: "",
        // product_title: "",
        // product_id: "",
        // order_no: "",
        // order_type: "",
        // shop_id:"",
        pageNum: 1,
        pageSize:20,
        orderStatus:undefined,
        skuId:0,
        title:'',
        productId:undefined,
        orderId:undefined,
        settleStatus:0,
        search:''
      },
      total: 0,
      tableData: []
    };
  },
  mounted() {
    this.form.sellerId = this.$route.query.shop_id;
    // if(!this.form.sellerId){
    //    this.form.sellerId = ''
    // }
    this.getOrderProductListData();
  },
  methods: {
    tc() {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor() {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
    changeStatus(e) {
      if (e === 0) {
        this.form.orderStatus = "";
      } else {
        this.form.orderStatus = e;
      }
      this.form.pageNum = 1;
      //重新获取商品订单列表
      this.getOrderProductListData();
    },

    //获取商品订单列表
    async getOrderProductListData() {
      // var url =
      //   "order_status=" +
      //   this.form.order_status +
      //   "&product_title=" +
      //   this.form.product_title +
      //   "&product_id=" +
      //   this.form.product_id +
      //   "&order_no=" +
      //   this.form.order_no +
      //   "&shop_id="+this.form.shop_id+
      //   "&order_type=" +this.form.order_type+
      //   "&page=" +
      //   this.form.page;
      let url = "pageNum="+this.form.pageNum+"&pageSize="+this.form.pageSize
      this.form.orderStatus?url+='&orderStatus='+this.form.orderStatus:''
      this.form.skuId?url+='&skuId='+this.form.skuId:''
      this.form.title?url+='&title='+this.form.title:''
      this.form.productId?url+='&productId='+this.form.productId:''
      this.form.orderId?url+='&orderId='+this.form.orderId:''
      this.form.settleStatus?url+='&settleStatus='+this.form.settleStatus:''
      this.form.search?url+='&search='+this.form.search:''


      let res = await shopMallOrderlist(url);
      console.log(res);
      this.total = res.data.total;
      this.tableData = res.data.list;
    },
    //根据关键词重新获取商品订单
    searchvouchlist() {
      this.form.pageNum = 1;
      this.getOrderProductListData();
    },
    pageChange(page) {
      this.form.pageNum = page;
      this.getOrderProductListData();
    },
    //详情
    openOrderDetail(id) {
      // store.dispatch("setShop", data);
      this.$router.push({path:"./shoporderdetail",query:{order_no:id}});
    }
  }
};
</script>

<style lang="scss" scoped>
.shop {
  padding: 20px;
  position: relative;

  .order_table {
    margin-top: 70px;
  }
  .shop_title {
    font-weight: 700;
  }
 
  .input {
    width: 150px;
  }
  .shop_name_row {
    float: right;
  }
  .search{
    float: right;
    margin-right: 10px;
  }
  // .search_name{
  //   position: absolute;
  //   top: 72px;
  //   right: 34px;
  // }
  .pagination {
    float: right;
  }
  .text_ordertype{
    display: inline-block;
    margin-left: 12px;
  }
  .detail_select{
     width: 120px;
  }
}
</style>